/**
 * 代理模式
 * ES6 Proxy语法
 */

const obj = {
    name: 'ycy',
    age: 25,
    phone: '123456'
}

const proxy = new Proxy(obj, {
    get(target, key) {
        if(key === 'phone') {
            return '111111'
        }
        return target[key]
    },
    set(target, key, value) {
        if(key === 'price') {
            if(value < 10000) {
                throw new Error('价格低了')
            }
        }
        target[key] = value
    }
})

console.log(proxy.phone);
// proxy.price = 100
proxy.price = 100000
console.log(proxy.price);